var t = s(require("../../../@babel/runtime/regenerator")),
  e = require("../../../@babel/runtime/helpers/asyncToGenerator"),
  a = s(require("../../../config/index")),
  n = (function (t) {
    if (t && t.__esModule) return t;
    if (null === t || ("object" != typeof t && "function" != typeof t))
      return { default: t };
    var e = u();
    if (e && e.has(t)) return e.get(t);
    var a = {},
      n = Object.defineProperty && Object.getOwnPropertyDescriptor;
    for (var r in t)
      if (Object.prototype.hasOwnProperty.call(t, r)) {
        var i = n ? Object.getOwnPropertyDescriptor(t, r) : null;
        i && (i.get || i.set) ? Object.defineProperty(a, r, i) : (a[r] = t[r]);
      }
    (a.default = t), e && e.set(t, a);
    return a;
  })(require("@/services/base/api")),
  r = require("@/utils/index"),
  i = require("@/services/user-service"),
  d = require("@/utils/jump"),
  o = s(require("@/config/page")),
  l = s(require("dayjs"));
function u() {
  if ("function" != typeof WeakMap) return null;
  var t = new WeakMap();
  return (
    (u = function () {
      return t;
    }),
    t
  );
}
function s(t) {
  return t && t.__esModule ? t : { default: t };
}
Page({
  data: {
    info: -1,
    CDN: a.default.CDN,
    title: "我的收藏",
    position: !1,
    background: "#FAF3E8",
    iconTheme: "black",
    titleColor: "#000",
    defaultImg: a.default.defaultImg,
    startX: 0,
    left: 0,
    delIndex: -1,
    list: [{ name: "位置" }, { name: "展览" }, { name: "藏品" }],
    isChecked: 0,
    pn: 1,
    rn: 10,
    isLoad: !0,
    type: 1,
    collectionList: [],
    longitude: 1,
    latitude: 2,
    isOver: !1,
    height: 0,
    total: 0,
    openId: "",
  },
  onShow: function () {
    var a = this;
    return e(
      t.default.mark(function n() {
        var r, d, o, l;
        return t.default.wrap(function (n) {
          for (;;)
            switch ((n.prev = n.next)) {
              case 0:
                return (
                  a.setData({ collectionList: [], pn: 1, isLoad: !0 }),
                  (r = a.createSelectorQuery().in(a))
                    .select("#c-title")
                    .boundingClientRect(),
                  r.exec(function (t) {
                    var e = t[0].height,
                      n = getApp().globalSystemInfo,
                      r = n.navBarHeight;
                    n.ios && (r += n.navBarExtendHeight);
                    var i = wx.getSystemInfoSync().windowHeight - r - e;
                    a.setData({ height: i });
                  }),
                  (n.next = 6),
                  (0, i.getUserId)()
                );
              case 6:
                (d = n.sent),
                  a.setData({ openId: d }),
                  (o = a),
                  (l = a.data.pn),
                  wx.getLocation({
                    type: "wgs84",
                    success: function (a) {
                      return e(
                        t.default.mark(function e() {
                          var n, r, i, d;
                          return t.default.wrap(function (t) {
                            for (;;)
                              switch ((t.prev = t.next)) {
                                case 0:
                                  return (
                                    o.setData({
                                      latitude: a.latitude,
                                      longitude: a.longitude,
                                    }),
                                    (t.next = 3),
                                    o.initData(l, o.data.type)
                                  );
                                case 3:
                                  (d = t.sent),
                                    o.setData({
                                      collectionList:
                                        null !== (n = d.data) &&
                                        void 0 !== n &&
                                        n.date
                                          ? d.data.date
                                          : [],
                                      isOver:
                                        null == d ||
                                        null === (r = d.data) ||
                                        void 0 === r ||
                                        null === (i = r.date) ||
                                        void 0 === i ||
                                        !i.length ||
                                        d.data.date.length >= o.data.total,
                                    });
                                case 5:
                                case "end":
                                  return t.stop();
                              }
                          }, e);
                        }),
                      )();
                    },
                    fail: function () {
                      return e(
                        t.default.mark(function e() {
                          var a, n, r, i;
                          return t.default.wrap(function (t) {
                            for (;;)
                              switch ((t.prev = t.next)) {
                                case 0:
                                  return (
                                    (t.next = 2), o.initData(l, o.data.type)
                                  );
                                case 2:
                                  (i = t.sent),
                                    o.setData({
                                      collectionList:
                                        null !== (a = i.data) &&
                                        void 0 !== a &&
                                        a.date
                                          ? i.data.date
                                          : [],
                                      isOver:
                                        null == i ||
                                        null === (n = i.data) ||
                                        void 0 === n ||
                                        null === (r = n.date) ||
                                        void 0 === r ||
                                        !r.length ||
                                        i.data.date.length >= o.data.total,
                                    });
                                case 4:
                                case "end":
                                  return t.stop();
                              }
                          }, e);
                        }),
                      )();
                    },
                  });
              case 11:
              case "end":
                return n.stop();
            }
        }, n);
      }),
    )();
  },
  initData: function (a, i) {
    var d = this;
    return e(
      t.default.mark(function e() {
        var o, u, s, c, f, p, h, v;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                return (
                  (c = d.data),
                  (f = c.longitude),
                  (p = c.latitude),
                  (h = c.openId),
                  (t.next = 3),
                  n.myCollectionList({
                    pn: a,
                    rn: 10,
                    type: i,
                    openId: h,
                    longitude: f,
                    latitude: p,
                  })
                );
              case 3:
                return (
                  (v = t.sent),
                  d.setData({
                    isLoad: !1,
                    total:
                      null != v &&
                      null !== (o = v.data) &&
                      void 0 !== o &&
                      o.total
                        ? v.data.total
                        : 0,
                  }),
                  null != v &&
                    null !== (u = v.data) &&
                    void 0 !== u &&
                    null !== (s = u.date) &&
                    void 0 !== s &&
                    s.length &&
                    (1 === i
                      ? v.data.date.map(function (t) {
                          return (
                            (t.distance = (0, r.getShowDistance)(t.distance)), t
                          );
                        })
                      : 2 === i &&
                        v.data.date.map(function (t) {
                          return (
                            t.data.category &&
                            2 === t.data.category &&
                            t.data.start_day &&
                            t.data.end_day
                              ? (0, l.default)().isBefore(t.data.start_day)
                                ? (t.data.onShow = 0)
                                : (0, l.default)().isAfter(t.data.start_day) &&
                                    (0, l.default)().isBefore(t.data.end_day)
                                  ? (t.data.onShow = 1)
                                  : (0, l.default)().isAfter(t.data.end_day) &&
                                    (t.data.onShow = 2)
                              : (t.data.onShow = 3),
                            t
                          );
                        })),
                  t.abrupt("return", v)
                );
              case 7:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  chooseCollectionType: function (a) {
    var n = this;
    return e(
      t.default.mark(function e() {
        var r, i, d, o;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                if (
                  ((r = a.currentTarget.dataset.index), n.data.isChecked === r)
                ) {
                  t.next = 6;
                  break;
                }
                return (t.next = 4), n.initData(1, r + 1);
              case 4:
                (o = t.sent),
                  n.setData({
                    isChecked: r,
                    delIndex: -1,
                    left: 0,
                    info: -1,
                    type: r + 1,
                    pn: 1,
                    collectionList:
                      null !== (i = o.data) && void 0 !== i && i.date
                        ? o.data.date
                        : [],
                    isOver:
                      null === (d = o.data.date) ||
                      void 0 === d ||
                      !d.length ||
                      o.data.date.length >= n.data.total,
                  });
              case 6:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  scrolltolower: function () {
    var a = this;
    return e(
      t.default.mark(function e() {
        var n, r, i, d, o, l, u;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                if (
                  ((n = a.data),
                  (r = n.isOver),
                  (i = n.collectionList),
                  (d = n.pn),
                  (o = n.type),
                  (l = n.total),
                  !r)
                ) {
                  t.next = 3;
                  break;
                }
                return t.abrupt("return");
              case 3:
                return (
                  a.setData({ isLoad: !0 }), (t.next = 6), a.initData(d + 1, o)
                );
              case 6:
                (u = t.sent),
                  a.setData({
                    pn: d + 1,
                    collectionList: i.concat(u.date),
                    isLoad: !1,
                  }),
                  a.data.collectionList.length >= l &&
                    a.setData({ isOver: !0 });
              case 9:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  touchmove: function (t) {
    var e = t.currentTarget.dataset.index,
      a = this.data.startX,
      n = t.changedTouches[0].clientX,
      r = this.data.delIndex;
    this.setData({ info: e }),
      Math.abs(n - a) > 80
        ? ((r = n < a ? e : -1), this.setData({ delIndex: r, left: 0 }))
        : this.setData({ delIndex: r, left: n - a });
  },
  touchend: function (t) {
    var e = this.data.startX,
      a = t.changedTouches[0].clientX,
      n = this.data.delIndex;
    Math.abs(a - e) < 80 &&
      a < e &&
      ((n = -1), this.setData({ delIndex: n, left: 0, info: -1 }));
  },
  touchstart: function (t) {
    this.setData({ startX: t.changedTouches[0].clientX, delIndex: -1 });
  },
  deleteCollectionInfo: function (a) {
    var r = this;
    return e(
      t.default.mark(function e() {
        var i, d, o, l, u, s, c, f, p, h;
        return t.default.wrap(function (t) {
          for (;;)
            switch ((t.prev = t.next)) {
              case 0:
                return (
                  (i = r.data),
                  (d = i.type),
                  (o = i.openId),
                  (l = a.currentTarget.dataset.item),
                  (u = ""),
                  (u =
                    1 === d
                      ? l.poi_id
                      : 2 === d
                        ? l.exhibition_id
                        : l.exhibit_id),
                  (t.next = 6),
                  n.saveOrCancelCollection({
                    category: d,
                    id: u,
                    openId: o,
                    operate: 0,
                  })
                );
              case 6:
                if (0 !== (null == (s = t.sent) ? void 0 : s.code)) {
                  t.next = 13;
                  break;
                }
                return (t.next = 10), r.initData(1, d);
              case 10:
                (h = t.sent),
                  r.setData({
                    pn: 1,
                    isOver:
                      null == h ||
                      null === (c = h.data) ||
                      void 0 === c ||
                      null === (f = c.date) ||
                      void 0 === f ||
                      !f.length ||
                      h.data.date.length >= r.data.total,
                    collectionList:
                      null != h &&
                      null !== (p = h.data) &&
                      void 0 !== p &&
                      p.date
                        ? h.data.date
                        : [],
                  }),
                  wx.showToast({
                    title: "取消收藏成功!",
                    icon: "none",
                    duration: 2500,
                  });
              case 13:
              case "end":
                return t.stop();
            }
        }, e);
      }),
    )();
  },
  toPage: function (t) {
    var e = this.data.type,
      a = t.currentTarget.dataset.item;
    console.log(a, e, a.data.poi_id),
      1 === e
        ? (0, d.navigateTo)(o.default.PAGE_TOUR_MAP_INDEX, {
            id: a.data.poi_id,
          })
        : 2 === e
          ? (0, d.navigateTo)(o.default.PAGE_RECOMMEND_EXHIBITION_CARD, {
              id: a.data.exhibition_id,
            })
          : (0, d.navigateTo)(
              o.default.PAGE_APPRECIATION_PAGES_CULTURAL_INDEX,
              { id: a.data.exhibit_id },
            );
  },
});
